import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/date_tool.dart';
import 'package:share_fit/generated/locales.g.dart';

enum DateType {
  day('day'),
  week('week'),
  month('month'),
  year('year'),
  all('all');

  final String name;

  const DateType(this.name);

  get i18nName {
    switch (name) {
      case 'day':
        return LocaleKeys.time_unit_day.ts;
      case 'week':
        return LocaleKeys.time_unit_week.ts;
      case 'month':
        return LocaleKeys.time_unit_month.ts;
      case 'year':
        return LocaleKeys.time_unit_year.ts;
      default:
        return LocaleKeys.sports_type_all.ts;
    }
  }

  get getToday {
    var now = DateTime.now();
    return DateTime(now.year, now.month, now.day);
  }

  get getWeekDays {
    DateTime now = DateTime.now();
    DateTime weekStart = now.subtract(Duration(days: now.weekday - 1));
    DateTime weekEnd = now.add(Duration(days: DateTime.daysPerWeek - now.weekday + 1));
    List<DateTime> dts = [];

    do {
      dts.add(DateTime(weekStart.year, weekStart.month, weekStart.day));
      weekStart = weekStart.add(const Duration(days: 1));
    } while (!DateTool.isSameDay(weekStart, weekEnd));
    return dts;
  }

  get getMonthDays {
    var now = DateTime.now();
    var dayCount = DateTime(now.year, now.month + 1, 0).day;
    List<DateTime> dts = [];

    for (var day = 1; day <= dayCount; day++) {
      dts.add(DateTime(now.year, now.month, day));
    }
    return dts;
  }
}
